package Sudoku3.solver;

import java.util.BitSet;

import Sudoku3.structure.*;

public class validator {
	
	private grid _g;
	
	public validator(grid g) {
		_g = g;
	}
	
	public boolean isValid() {

		
		//iterate through the group types
		for (Class <? extends group> grouptype : _g.getGroupTypes()) {
			//iterate through groupIDs
			for (int i = 0; i < 9; i++) {
				
				group grp;
				if (grouptype == row.class) { grp = _g.getRow(i); }
				else if (grouptype == col.class) { grp = _g.getCol(i); }
				else { grp = _g.getBlk(i); }
				
				//iterate through values
				
				for (int v = 1; v < 10; v++) {
					BitSet m = new BitSet(9);
					//iterate through cells
					for (cell c : grp) {
						if (c.getValue() == v) {
							m.set(grp.indexOf(c));
						}
					}
				if (m.cardinality() > 1) { return false; }
				}
				
				
			}
		}
		
		
		return true;
	}

}
